package com.work.rochegroupproperty.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.validation.constraints.*;

import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@TableName("todolist")
public class Todo implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id; // 自增主键

    @NotBlank(message = "标题不能为空")
    @Size(max = 255, message = "标题长度不能超过255个字符")
    private String title; // 待办事项标题

    private String description; // 待办事项描述

    private LocalDateTime createdAt; // 创建时间（系统自动填充）

    @NotBlank(message = "状态不能为空")
    @Pattern(regexp = "pending|in_progress|completed|archived", message = "无效的状态值")
    private String status; // 状态（枚举）

    @NotNull(message = "优先级不能为空")
    @Min(value = 1, message = "优先级不能小于1")
    @Max(value = 5, message = "优先级不能大于5")
    private Integer priority; // 优先级（范围1-5）

    @Future(message = "截止日期必须是将来的时间")
    private LocalDateTime dueDate; // 截止日期

    @NotNull(message = "所属用户ID不能为空")
    @Positive(message = "所属用户ID必须为正整数")
    private Integer belongingUserId; // 所属用户ID

    public enum TodoStatus {
        PENDING("pending"),
        IN_PROGRESS("in_progress"),
        COMPLETED("completed"),
        ARCHIVED("archived");

        private final String dbValue;

        TodoStatus(String dbValue) {
            this.dbValue = dbValue;
        }

        public String getDbValue() {
            return dbValue;
        }
    }
}
